clear all
set more off, perm
set mem 10000000
set matsize 10000
version 13

************************************************************************************* 
*** Table and figures for JPE revisions: first-stage Census electricity variables ***
************************************************************************************* 

** Set file paths
do "$path_code/paths.do"

** Set graph scheme
cd "$path/code/analyze"
set scheme fb, perm

********************************************************************************
********************************************************************************

** Table 2: First-stage RD results for VD electricity
{
cap file close tablewrite
use "$results/RDROBUST_fs_vdelec.dta", clear
keep if fs_step==1
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFE*"
assert kernel=="Triangular"
assert polynomial==1
assert fals==""

gen c = .
replace c = 1 if yvar=="vd_pwr_d_dom_11" 
replace c = 2 if yvar=="vd_pwr_d_agr_11"
replace c = 3 if yvar=="vd_pwr_d_com_11" 
replace c = 4 if yvar=="vd_pwr_d_all_11"
replace c = 5 if yvar=="vd_pwr_h_dom_11" 
replace c = 6 if yvar=="vd_pwr_h_agr_11"
replace c = 7 if yvar=="vd_pwr_h_com_11" 
replace c = 8 if yvar=="vd_pwr_h_all_11"
assert c!=.	
sort c

forvalues c = 1/8 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	
	
   // MAKE TABLE
file open tablewrite using "$textab/table_rd_vdelec.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Village-level RD in 2011 electricity access, by sector}" _n
file write tablewrite "\label{tab:rd_vdelec}" _n
file write tablewrite "\small" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{4}{c}{Outcome: Village-level electricity access} \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.8cm}" _n
file write tablewrite "\\" _n
file write tablewrite "& ~Domestic~ & Agricultural & Commercial & All 3 sectors \\" _n
file write tablewrite "& (1) & (2) & (3) & (4) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\"
file write tablewrite "\textbf{A.} \underline{Dummy for any power access} \\ " _n
file write tablewrite "[0.4em] " _n
file write tablewrite "~~~~\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big]$ & " _n
file write tablewrite "$`beta1'$`stars1' & $`beta2'$`stars2' & $`beta3'$`stars3' & $`beta4'$`stars4' \\" _n
file write tablewrite "& $(`se1')$ & $(`se2')$ & $(`se3')$ & $(`se4')$ \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "~~~~Mean of dep var (\$<300\$)~ & `ymean1' & `ymean2' & `ymean3' & `ymean4' \\ " _n
file write tablewrite "~~~~Optimal bandwidth & `bw1' & `bw2' & `bw3' & `bw4' \\ " _n
file write tablewrite "~~~~Village observations &`nobs1' & `nobs2' & `nobs3' & `nobs4' \\ " _n
file write tablewrite "[1.5em] " _n
file write tablewrite "\textbf{B.} \underline{Hours/day of power supply} \\ "_n
file write tablewrite "[0.4em] " _n
file write tablewrite "~~~~\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big]$ & " _n
file write tablewrite "$`beta5'$`stars5' & $`beta6'$`stars6' & $`beta7'$`stars7' & $`beta8'$`stars8' \\" _n
file write tablewrite "& $(`se5')$ & $(`se6')$ & $(`se7')$ & $(`se8')$ \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "~~~~Mean of dep var (\$<300\$)~ & `ymean5' & `ymean6' & `ymean7' & `ymean8' \\ " _n
file write tablewrite "~~~~Optimal bandwidth & `bw5' & `bw6' & `bw7' & `bw8' \\ " _n
file write tablewrite "~~~~Village observations &`nobs5' & `nobs6' & `nobs7' & `nobs8' \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- \texttt{rdrobust} estimates use linear polynomials, triangular kernels, " _n
file write tablewrite "MSE-optimal bandwidth, and nearest-neighbor standard errors. Regression samples include within-bandwidth " _n
file write tablewrite "single-habitation villages in RGGVY 10th-Plan districts (i.e.\ the first wave of RGGVY project implementation, " _n
file write tablewrite "for which 300 people is the relevant 2001 population-based eligibility cutoff). " _n
file write tablewrite "Each regression controls for pre-2005 nighttime brightness at the village level, and state fixed effects. " _n
file write tablewrite "Optimal bandwidths are symmetric above and below the 300-person cutoff, and we report means of the dependent " _n
file write tablewrite "variable for villages below the cutoff. " _n
file write tablewrite "In Panel A, outcomes are dummy variables for electricity access at the village level. " _n
file write tablewrite "In Panel B, outcomes are the average hours of power available per day in the village. " _n
file write tablewrite "Results are robust to alternative controls, kernels, bandwidth algorithms, and standard errors. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Figure 4: First-stage RD plots for VD electricity
{
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_d_com_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_d_com_11_fs_preferred_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_h_com_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_h_com_11_fs_preferred_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_d_all_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_d_all_11_fs_preferred_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_h_all_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_h_all_11_fs_preferred_inreg_10.pdf" , replace

   // MAKE FIGURE
file open tablewrite using "$texfig/figure_rd_vdelec.tex", write text replace
 
file write tablewrite "\begin{figure}[p]\centering" _n
file write tablewrite "\caption{Village-level RDs in 2011 electricity access}" _n
file write tablewrite "\label{fig:rd_vdelec}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_d_com_11_fs_preferred_inreg_10.pdf}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_h_com_11_fs_preferred_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_d_all_11_fs_preferred_inreg_10.pdf}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_h_all_11_fs_preferred_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- The top RD plots correspond to Column (3) of Table \ref{tab:rd_vdelec}. " _n
file write tablewrite "The bottom RD plots correspond to Column (4) of Table \ref{tab:rd_vdelec}. " _n
file write tablewrite "See table notes for details. Appendix Figure \ref*{fig:rd_vdelec_bonus} displays " _n
file write tablewrite "RD plots corresponding to the other four regressions in Table \ref{tab:rd_vdelec}." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Table A1: Difference in disconituities for VD electricity
{
cap file close tablewrite
use "$results/diff_in_disc_vdelec.dta", clear
keep if beta!=.
assert _N==2

gen c = .
replace c = 1 if bw==150
replace c = 2 if bw==100
assert c!=.	
sort c

forvalues c = 1/2 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if  pvalue[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local nobs`c' = string(nobs[`c'],"%9.0fc")
	local bw`c' = string(bw[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	
	
   // MAKE TABLE
file open tablewrite using "$textab/table_diff_in_disc_vdelec.tex", write text replace
 
file write tablewrite "\begin{table}[h!]\centering" _n
file write tablewrite "\caption{Difference in discontinuities -- village-level electricity access}" _n
file write tablewrite "\label{tab:diff_in_disc_vdelec}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{2}{c}{Dummy for power access, all 3 sectors} \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-3} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite "\\" _n
file write tablewrite "&~~~~~~~~~~~ (1) ~~~~~~~~~~~& (2) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "~~~~\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big] \times \mathbf{1}\big[2011\big]$ ~~& " _n
file write tablewrite "$`beta1'$`stars1' & $`beta2'$`stars2'  \\" _n
file write tablewrite "& $(`se1')$ & $(`se2')$  \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "~~~~Mean of dep var & `ymean1' & `ymean2' \\ " _n
file write tablewrite "~~~~RD bandwidth & `bw1' & `bw2' \\ " _n
file write tablewrite "~~~~Village-year observations &`nobs1' & `nobs2'  \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Difference-in-discontinuities estimates applying " _n
file write tablewrite "Equation (\ref{eq:diff_in_disc}) to a two-period Census panel. We report the " _n
file write tablewrite "differential RD LATE for 2011, relative to the RD LATE in 2001 (the omitted year). " _n
file write tablewrite "The outcome is a dummy variable for electricity access in all sectors of the " _n
file write tablewrite "village economy, the only statistically significant outcome from " _n
file write tablewrite "Table \ref*{tab:rd_vdelec} that we  observe in the 2001 Census. " _n
file write tablewrite "Each regression imposes a common RD bandwidth across both 2001 and 2011 Census years; " _n
file write tablewrite "we weight observations by distance from the 300-person cutoff using a triangular kernel, " _n
file write tablewrite "which aligns with our preferred \texttt{rdrobust} specification. " _n
file write tablewrite "Regressions control for separate linear polynomials in the running variable for each year " _n
file write tablewrite "(both above and below the cutoff), village fixed effects, and district-by-year fixed effects." _n
file write tablewrite "Our estimation sample includes within-bandwidth single-habitation villages in RGGVY 10th-Plan districts. " _n
file write tablewrite "Standard errors are clustered by Census block. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n


file close tablewrite


}

********************************************************************************
********************************************************************************

** Table A2: DD for VD electricity, village level
{
use "${results}/dd_vdelec_pooled.dta", clear
assert _N==12
keep if fes=="year pca01_id exp05_st_4ile#c.year exp05_ntl_10ile#c.year st_code#c.year"
assert _N==4

gen c = .
replace c = 1 if yvar=="vd_pwr_d_any" 
replace c = 2 if yvar=="vd_pwr_d_dom" 
replace c = 3 if yvar=="vd_pwr_d_agr" 
replace c = 4 if yvar=="vd_pwr_d_all" 
assert c!=.	
sort c

forvalues c = 1/4 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if  pvalue[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local nobs`c' = string(nobs[`c']/1e6,"%9.2f") + "M"
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	


   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_dd_vdelec.tex", write text replace

file write tablewrite "\begin{table}[h!]\centering " _n
file write tablewrite "\caption{Village-level DD of electricity access dummies}" _n
file write tablewrite "\label{tab:dd_vdelec}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc}" _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{4}{c}{Outcome: Dummy for any power access in village, by sector} \\ " _n
file write tablewrite "\vspace{-0.42cm}" _n
file write tablewrite "\\" _n
file write tablewrite " \cline{2-5} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite " \\" _n
file write tablewrite " & Any 1 sector & Domestic & Agricultural & All sectors \\ " _n
file write tablewrite "& (1) & (2) & (3) & (4) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\$\mathbf{1}\big[\text{10th-Plan district}\big] \times \mathbf{1}\big[2011\big]\$ ~ &  " _n
file write tablewrite "\$`beta1'$`stars1' & $`beta2'$`stars2' & $`beta3'$`stars3' & $`beta4'$`stars4' \\" _n
file write tablewrite "& ~~~~$(`se1')$~~~~ & ~~~~$(`se2')$~~~~ & ~~~~$(`se3')$~~~~ & ~~~~$(`se4')$~~~~ \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "Mean of dep var & `ymean1' & `ymean2' & `ymean3' & `ymean4' \\" _n
file write tablewrite "Village-year observations &`nobs1' & `nobs2' & `nobs3' & `nobs4' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- " _n
file write tablewrite "Village-level DD using 2001 and 2011 Census dummy variables for electricity access. " _n
file write tablewrite "Unfortunately, the 2001 Census did not collect information on electricity access for commercial use, " _n
file write tablewrite "meaning we cannot estimate that DD model. Missing data from the 2001 Census prevent us from " _n
file write tablewrite "constructing the \`\`all sector'' dummy variable for roughly 22\% of villages. " _n
file write tablewrite "All regressions include: district fixed effects; year fixed effects; state-specific linear trends; " _n
file write tablewrite "linear trends in state quartiles of 2005 household expenditures per capita; " _n 
file write tablewrite "and linear trends in national deciles of 2005 household expenditures per capita " _n
file write tablewrite "(trends in NSS expenditure quantiles align with our NSS DD specification " _n
file write tablewrite "from Table \ref*{tab:nss_first_stage}). " _n
file write tablewrite "Estimation samples include villages in 10th-Plan districts, 11th-Plan districts, " _n
file write tablewrite "and non-RGGVY districts, without restricting village size. " _n
file write tablewrite "Standard errors are clustered at the district level." _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite
}

********************************************************************************
********************************************************************************

** Table A3: DD for VD electricity, district level
{
use "${results}/dd_vdelec_distlevel.dta", clear
assert _N==12
keep if fes=="year stdt exp05_st_4ile#c.year exp05_ntl_10ile#c.year st_code#c.year"
assert _N==4

gen c = .
replace c = 1 if yvar=="vd_pwr_d_any" 
replace c = 2 if yvar=="vd_pwr_d_dom" 
replace c = 3 if yvar=="vd_pwr_d_agr" 
replace c = 4 if yvar=="vd_pwr_d_all" 
assert c!=.	
sort c

forvalues c = 1/4 {
		
	local beta`c' = string(beta[`c'],"%9.3f")
	local se`c' = string(se[`c'],"%9.3f")
	if pvalue[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if  pvalue[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pvalue[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local nobs`c' = string(nobs[`c'],"%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	


   // MAKE TABLE
cap file close tablewrite
file open tablewrite using "$textab/table_dd_dist_vdelec.tex", write text replace

file write tablewrite "\begin{table}[h!]\centering " _n
file write tablewrite "\caption{District-level DD of electricity access dummies}" _n
file write tablewrite "\label{tab:dd_dist_vdelec}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc}" _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{4}{c}{Outcome: Share of villages with any power access, by sector} \\ " _n
file write tablewrite "\vspace{-0.42cm}" _n
file write tablewrite "\\" _n
file write tablewrite " \cline{2-5} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite " \\" _n
file write tablewrite " & Any 1 sector & Domestic & Agricultural & All sectors \\ " _n
file write tablewrite "& (1) & (2) & (3) & (4) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\$\mathbf{1}\big[\text{10th-Plan district}\big] \times \mathbf{1}\big[2011\big]\$ &~ " _n
file write tablewrite "\$`beta1'$`stars1' & $`beta2'$`stars2' & $`beta3'$`stars3' & $`beta4'$`stars4' \\" _n
file write tablewrite "& ~~~~$(`se1')$~~~~ & ~~~~$(`se2')$~~~~ & ~~~~$(`se3')$~~~~ & ~~~~$(`se4')$~~~~ \\" _n
file write tablewrite "[0.8em] " _n
file write tablewrite "Mean of dep var & `ymean1' & `ymean2' & `ymean3' & `ymean4' \\" _n
file write tablewrite "District-year observations &`nobs1' & `nobs2' & `nobs3' & `nobs4' \\" _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This table replicates Table \ref{tab:dd_vdelec} at the district level, " _n
file write tablewrite "rather than the village level. We collapse the 2-wave Census panel of villages weighting by " _n
file write tablewrite "the number of rural households in each district (which aligns with NSS sampling weights).  " _n
file write tablewrite "All regressions include: district fixed effects; year fixed effects; state-specific linear trends; " _n
file write tablewrite "linear trends in state quartiles of 2005 household expenditures per capita; " _n 
file write tablewrite "and linear trends in national deciles of 2005 household expenditures per capita. " _n
file write tablewrite "Estimation samples include villages in 10th-Plan districts, 11th-Plan districts, " _n
file write tablewrite "and non-RGGVY districts, without restricting village size. " _n
file write tablewrite "Standard errors clustered at the district level." _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite
}

********************************************************************************
********************************************************************************

** Figure A2: DD for VD electricity, village level by population bins
{
use "${results}/dd_vdelec_popbins.dta", clear
keep if fes=="year#popbin pca01_id exp05_st_4ile#c.year exp05_ntl_10ile#c.year st_code#c.year"
assert _N==4

gen c = .
replace c = 1 if yvar=="vd_pwr_d_any" 
replace c = 2 if yvar=="vd_pwr_d_dom" 
replace c = 3 if yvar=="vd_pwr_d_agr" 
replace c = 4 if yvar=="vd_pwr_d_all" 
assert c!=.	
sort c

drop fes vce ymean nobs nclust rmse
reshape long beta se tscore pvalue ci95_lo ci95_hi, i(yvar c) j(pop) string
replace pop = subinstr(pop,"_"," ",2)
replace pop = word(pop,1)
destring pop, replace
replace pop = pop + 250
replace pop = pop - 75 if c==1
replace pop = pop - 25 if c==2
replace pop = pop + 25 if c==3
replace pop = pop + 75 if c==4

twoway ///
	(rspike ci95_hi ci95_lo pop if c==1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(rspike ci95_hi ci95_lo pop if c==2, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(rspike ci95_hi ci95_lo pop if c==3, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(rspike ci95_hi ci95_lo pop if c==4, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta pop if c==1, msize(medsmall) mc(midblue) msymbol(O)) ///
	(scatter beta pop if c==2, msize(medsmall) mlc(navy) mfc(white) msymbol(T)) ///
	(scatter beta pop if c==3, msize(medsmall) mc(eltblue) msymbol(S)) ///
	(scatter beta pop if c==4, msize(medsmall) mc(midblue) msymbol(X)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("Binned DD coefficient (95% CI)") xtitle("Village population bin") ///
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(0(0.05)0.15,nogrid angle(0)) ///yscale(range(-0.125 0.4)) ///
	xlabel(0 500 1000 1500 2000 2500 3000 "3000+", labsize(medsmall)) ///
 	legend(order(5 "Any 1 sector  " 6 "Domestic  " 7 "Agricultural  " 8 "All 3 sectors") c(4) pos(6)) /// 
	aspect(0.35)

graph export "$texfig/figure_dd_vdelec_by_popbin.pdf", replace 
	
	 
   // MAKE FIGURE
cap file close tablewrite
file open tablewrite using "$texfig/figure_dd_vdelec_by_popbin.tex", write text replace

file write tablewrite "\begin{figure}[h!]\centering " _n
file write tablewrite "\caption{Village-level DD of electricity access dummies, by village population bin}" _n
file write tablewrite "\label{fig:dd_vdelec_by_popbin}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\includegraphics[width=0.61\textwidth, trim={0 17mm 0 15mm}, clip]{${texfig_short}/figure_dd_vdelec_by_popbin.pdf} " _n
file write tablewrite "\vspace{-5mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This figure plots binned DD coefficients " _n
file write tablewrite "for power access by sector" _n
file write tablewrite "We estimate four DD regressions analogous to those in Table \ref{tab:dd_vdelec}. " _n
file write tablewrite "Each regression interacts the DD coefficient with 500-person bins in 2001 village population " _n
file write tablewrite "(\$\le\$500, 501--1000, \dots, 2501--3000, \$>\$3000). " _n
file write tablewrite "We interact year fixed effects with population bins, and also include village fixed effects, " _n
file write tablewrite "both sets of 2005 expenditure trends, and state-specific trends. " _n
file write tablewrite "Whiskers display 95\% confidence intervals, with standard errors clustered by district. " _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite
}

********************************************************************************
********************************************************************************

** Figure A4: RD for VD electricity, plots for domestic and agricultural sectors
{
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_d_dom_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_d_dom_11_fs_preferred_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_h_dom_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_h_dom_11_fs_preferred_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_d_agr_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_d_agr_11_fs_preferred_inreg_10.pdf" , replace
copy "${results}/RDROBUST plots fs vdelec/vd_pwr_h_agr_11_fs_preferred_inreg_10.pdf" ///
		"${texfig}/vd_pwr_h_agr_11_fs_preferred_inreg_10.pdf" , replace

   // MAKE FIGURE
file open tablewrite using "$texfig/figure_rd_vdelec_bonus.tex", write text replace
 
file write tablewrite "\begin{figure}[p]\centering" _n
file write tablewrite "\caption{Village-level RDs in 2011 electricity access, domestic and agricultural sectors}" _n
file write tablewrite "\label{fig:rd_vdelec_bonus}" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_d_dom_11_fs_preferred_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_h_dom_11_fs_preferred_inreg_10.pdf}\\" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_d_agr_11_fs_preferred_inreg_10.pdf}~" _n
file write tablewrite "\includegraphics[width=0.495\textwidth]{${texfig_short}/vd_pwr_h_agr_11_fs_preferred_inreg_10.pdf}\\" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This figure complements Figure \ref*{fig:rd_vdelec}, with RD plots " _n
file write tablewrite "corresponding to Columns (1)--(2) of Table \ref*{tab:rd_vdelec}." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Table A12: RD for VD electricity, districts with high-intensity RGGVY implementation
{
cap file close tablewrite
use "$results/RDROBUST_fs_vdelec_dpr.dta", clear
keep if fs_step==1
keep if dprtag=="hi_vill"
assert ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20"
assert fe=="STFE*"
assert kernel=="Triangular"
assert polynomial==1

gen c = .
replace c = 1 if yvar=="vd_pwr_d_dom_11" 
replace c = 2 if yvar=="vd_pwr_d_agr_11"
replace c = 3 if yvar=="vd_pwr_d_com_11" 
replace c = 4 if yvar=="vd_pwr_d_all_11"
replace c = 5 if yvar=="vd_pwr_h_dom_11" 
replace c = 6 if yvar=="vd_pwr_h_agr_11"
replace c = 7 if yvar=="vd_pwr_h_com_11" 
replace c = 8 if yvar=="vd_pwr_h_all_11"
assert c!=.	
sort c

forvalues c = 1/8 {
		
	local beta`c' = string(beta_robust[`c'],"%9.3f")
	local se`c' = string(se_robust[`c'],"%9.3f")
	if pval_robust[`c'] <= 0.01 {
		local stars`c' = "$^{***}$"
	}
	else if pval_robust[`c'] <= 0.05 {
		local stars`c' = "$^{**}$"
	}
	else if pval_robust[`c'] <= 0.10 {
		local stars`c' = "$^{*}$"
	}
	else {
		local stars`c' = ""
	}

	local nobs`c' = string(nobs_left[`c'] + nobs_right[`c'],"%9.0fc")
	local bw`c' = string(bw_lo[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	
	
   // MAKE TABLE
file open tablewrite using "$textab/table_rd_vdelec_hi_intens.tex", write text replace
 
file write tablewrite "\begin{table}[h!]\centering" _n
file write tablewrite "\caption{Village-level RD in 2011 electricity access, high-intensity districts}" _n
file write tablewrite "\label{tab:rd_vdelec_hi_intens}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{4}{c}{Outcome: Village-level electricity access} \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-5} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite "\\" _n
file write tablewrite "& ~Domestic~ & Agricultural & Commercial & All 3 sectors \\" _n
file write tablewrite "& (1) & (2) & (3) & (4) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\textbf{A.} \underline{Dummy for any power access} \\ " _n
file write tablewrite "[0.2em] " _n
file write tablewrite "~~~~\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big]$ & " _n
file write tablewrite "$`beta1'$`stars1' & $`beta2'$`stars2' & $`beta3'$`stars3' & $`beta4'$`stars4' \\" _n
file write tablewrite "& $(`se1')$ & $(`se2')$ & $(`se3')$ & $(`se4')$ \\" _n
file write tablewrite "[0.5em] " _n
file write tablewrite "~~~~Mean of dep var (\$<300\$)~ & `ymean1' & `ymean2' & `ymean3' & `ymean4' \\ " _n
file write tablewrite "~~~~Optimal bandwidth & `bw1' & `bw2' & `bw3' & `bw4' \\ " _n
file write tablewrite "~~~~Village observations &`nobs1' & `nobs2' & `nobs3' & `nobs4' \\ " _n
file write tablewrite "[1.3em] " _n
file write tablewrite "\textbf{B.} \underline{Hours/day of power supply} \\ "_n
file write tablewrite "[0.2em] " _n
file write tablewrite "~~~~\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big]$ & " _n
file write tablewrite "$`beta5'$`stars5' & $`beta6'$`stars6' & $`beta7'$`stars7' & $`beta8'$`stars8' \\" _n
file write tablewrite "& $(`se5')$ & $(`se6')$ & $(`se7')$ & $(`se8')$ \\" _n
file write tablewrite "[0.5em] " _n
file write tablewrite "~~~~Mean of dep var (\$<300\$)~ & `ymean5' & `ymean6' & `ymean7' & `ymean8' \\ " _n
file write tablewrite "~~~~Optimal bandwidth & `bw5' & `bw6' & `bw7' & `bw8' \\ " _n
file write tablewrite "~~~~Village observations &`nobs5' & `nobs6' & `nobs7' & `nobs8' \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Regressions are identical to those in Table \ref*{tab:rd_vdelec}, " _n
file write tablewrite "except that we restrict the sample to the subset of RGGVY 10th-Plan districts where the program " _n
file write tablewrite "treated at least 60\% of all villages in the district (per RGGVY district-level " _n
file write tablewrite "implementation data). " _n
file write tablewrite "This reduces the main RD sample from 130 districts in 12 states to 90 districts in 11 states. " _n
file write tablewrite "See notes under Table \ref*{tab:rd_vdelec} for further details. " _n
file write tablewrite "Results are robust to alternative kernels and bandwidth algorithms. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n

file close tablewrite


}

********************************************************************************
********************************************************************************

** Table A18: Difference in disconituities for VD electricity, split by over/under 10 hours/day of power
{
cap file close tablewrite
use "$results/diff_in_disc_vdelec.dta", clear
keep if beta==.
assert _N==2
dropmiss, force

gen c = .
replace c = 1 if bw==150
replace c = 2 if bw==100
assert c!=.	
sort c

forvalues c = 1/2 {
		
	local beta_hi`c' = string(beta_hi[`c'],"%9.3f")
	local se_hi`c' = string(se_hi[`c'],"%9.3f")
	if pvalue_hi[`c'] <= 0.01 {
		local stars_hi`c' = "$^{***}$"
	}
	else if  pvalue_hi[`c'] <= 0.05 {
		local stars_hi`c' = "$^{**}$"
	}
	else if pvalue_hi[`c'] <= 0.10 {
		local stars_hi`c' = "$^{*}$"
	}
	else {
		local stars_hi`c' = ""
	}

	local beta_lo`c' = string(beta_lo[`c'],"%9.3f")
	local se_lo`c' = string(se_lo[`c'],"%9.3f")
	if pvalue_lo[`c'] <= 0.01 {
		local stars_lo`c' = "$^{***}$"
	}
	else if  pvalue_lo[`c'] <= 0.05 {
		local stars_lo`c' = "$^{**}$"
	}
	else if pvalue_lo[`c'] <= 0.10 {
		local stars_lo`c' = "$^{*}$"
	}
	else {
		local stars_lo`c' = ""
	}

	local pval_eq`c' = string(pval_equal[`c'],"%9.3f")
	local nobs`c' = string(nobs[`c'],"%9.0fc")
	local bw`c' = string(bw[`c'], "%9.0f")
	local ymean`c' = string(ymean[`c'],"%9.3f")
}	
	
   // MAKE TABLE
file open tablewrite using "$textab/table_diff_in_disc_vdelec_hours.tex", write text replace
 
file write tablewrite "\begin{table}[p]\centering" _n
file write tablewrite "\caption{Difference in discontinuities -- village-level electricity access \$\times\$ high/low power supply}" _n
file write tablewrite "\label{tab:diff_in_disc_vdelec_hours}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\small" _n
file write tablewrite "\begin{tabular}{lccccccc} " _n
file write tablewrite "\hline" _n
file write tablewrite "& \multicolumn{2}{c}{Dummy for power access, all 3 sectors} \\" _n
file write tablewrite "\vspace{-0.40cm}" _n
file write tablewrite "\\" _n
file write tablewrite "\cline{2-3} \\" _n
file write tablewrite "\vspace{-0.80cm}" _n
file write tablewrite "\\" _n
file write tablewrite "&~~~~~~~~~ (1) ~~~~~~~~~& (2) \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big] \times \mathbf{1}\big[2011\big] \times \mathbf{1}\big[\ge 10 \text{ hours/day}\big] $ ~ & " _n
file write tablewrite "$`beta_hi1'$`stars_hi1' & $`beta_hi2'$`stars_hi2'  \\" _n
file write tablewrite "& $(`se_hi1')$ & $(`se_hi2')$  \\" _n
file write tablewrite "[0.5em] " _n
file write tablewrite "\$\mathbf{1}\big[\text{2001 pop \$\ge 300\$}\big] \times \mathbf{1}\big[2011\big] \times \mathbf{1}\big[< 10 \text{ hours/day}\big] $ ~ & " _n
file write tablewrite "$`beta_lo1'$`stars_lo1' & $`beta_lo2'$`stars_lo2'  \\" _n
file write tablewrite "& $(`se_lo1')$ & $(`se_lo2')$  \\" _n
file write tablewrite "[0.5em] " _n
file write tablewrite "\$p\$-value on test of equality & `pval_eq1' & `pval_eq2'  \\ " _n
file write tablewrite "[0.8em] " _n
file write tablewrite "Mean of dep var & `ymean1' & `ymean2' \\ " _n
file write tablewrite "RD bandwidth & `bw1' & `bw2' \\ " _n
file write tablewrite "Village-year observations &`nobs1' & `nobs2'  \\ " _n
file write tablewrite "\hline" _n
file write tablewrite "\end{tabular} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Difference-in-discontinuities estimates are identical to " _n
file write tablewrite "those in Table \ref{tab:diff_in_disc_vdelec}, except that we interact the RD indicator " _n
file write tablewrite "with dummies for districts where rural villages receive over/under 10 hours per day of power supply. " _n
file write tablewrite "We calculate this variable by averaging hours of all-sector power (from the 2011 Census, at the village level) " _n
file write tablewrite "over all electrified villages in each district. " _n
file write tablewrite "We report \$p\$-values for a test of equality of the two interacted DD coefficients. " _n
file write tablewrite "Both regressions include village fixed effects and district-by-year fixed effects. " _n
file write tablewrite "Standard errors are clustered by Census block. " _n
file write tablewrite "Significance: *** \$p < 0.01\$, ** \$p < 0.05\$, * \$p < 0.10\$." _n
file write tablewrite "}" _n
file write tablewrite "\end{table}" _n


file close tablewrite


}

********************************************************************************
********************************************************************************

** Figure B1: RD for VD electricity, sensitivities
{

use "${results}/RDROBUST_fs_vdelec.dta", clear
keep if yvar=="vd_pwr_d_com_11"
keep if fals==""
keep if word(ifs,1)=="in_fs_sample==1"
gen c = .
replace c = 1 if ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20" & fs_step==1
replace c = 2 if kernel=="Epanechnikov" & polynomial==1
replace c = 3 if kernel=="Uniform" & polynomial==1
replace c = 4 if bwmethod=="msesum"
replace c = 5 if bwmethod=="cerrd"
replace c = 6 if vce=="vce(nncluster stdtbk)"
replace c = 7 if vce=="vce(cluster stdtbk)"
replace c = 8 if vce=="vce(cluster stdt)"
replace c = 9 if fe==""
replace c = 10 if fe=="DTFE*"
replace c = 11 if kernel=="Triangular" & polynomial==2
replace c = 12 if ifs=="in_fs_sample==1 & lights_diff<20"
replace c = 13 if ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<50"
keep if c!=.
unique c
assert r(unique)==r(N) & r(N)==13

gen lci10 = beta_robust - 1.645*se_robust
gen asterisk = .
replace asterisk = -0.01 if lci10>0 & lci_robust<0

twoway (rspike uci_robust lci_robust c if c==1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta_robust c if c==1, msize(small) mc(midblue) msymbol(O)) ///
	(rspike uci_robust lci_robust c if c>1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta_robust c if c>1, msize(small) mlc(navy) mfc(white) msymbol(T)) ///
	(scatter asterisk c , msize(small) mlc(gs10) mfc(white) msymbol(+)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("RD coefficient (95% CI)", size(vsmall)) xtitle("") ///
	title("Outcome: Dummy for any commercial power", color(black) size(vsmall)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(0(0.02)0.1,nogrid angle(0) labsize(vsmall)) yscale(titlegap(*-4) range(-0.01 0.1)) ///
	xlabel( 1 `" "Preferred" "'  ///
			2 `" "Kernel:" "Epanech-" "nikov" "' ///
			3 `" "Kernel:" "Uniform" "' ///
			4 `" "BW:" "MSE" "(sum)" "' ///
			5 `" "BW:" "CER" "(common)" "' ///
			6 `" "NN cluster" "by block" "' ///
			7 `" "Cluster" "by block" "' ///
			8 `" "Cluster" "by district" "' ///
			9 `" "No" "FEs" "' ///
			10 `" "District" "FEs" "' ///
			11 `" "2nd-order" "polynomial" "' ///
			12 `" "With" "pop" "mismatches" "' ///
			13 `" "With" "lights" " outliers" "' ///
			, labsize(vsmall)) ///
	legend(off) aspect(0.25)

graph export "$texfig/rd_vdelec_coeffs_sens_dcom.pdf", replace 

***

use "${results}/RDROBUST_fs_vdelec.dta", clear
keep if yvar=="vd_pwr_h_com_11"
keep if fals==""
keep if word(ifs,1)=="in_fs_sample==1"
gen c = .
replace c = 1 if ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20" & fs_step==1
replace c = 2 if kernel=="Epanechnikov" & polynomial==1
replace c = 3 if kernel=="Uniform" & polynomial==1
replace c = 4 if bwmethod=="msesum"
replace c = 5 if bwmethod=="cerrd"
replace c = 6 if vce=="vce(nncluster stdtbk)"
replace c = 7 if vce=="vce(cluster stdtbk)"
replace c = 8 if vce=="vce(cluster stdt)"
replace c = 9 if fe==""
replace c = 10 if fe=="DTFEh*"
replace c = 11 if kernel=="Triangular" & polynomial==2
replace c = 12 if ifs=="in_fs_sample==1 & lights_diff<20"
replace c = 13 if ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<50"
keep if c!=.
unique c
assert r(unique)==r(N) & r(N)==13

gen lci10 = beta_robust - 1.645*se_robust
gen asterisk = .
replace asterisk = -0.1 if lci10>0 & lci_robust<0

twoway (rspike uci_robust lci_robust c if c==1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta_robust c if c==1, msize(small) mc(midblue) msymbol(O)) ///
	(rspike uci_robust lci_robust c if c>1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta_robust c if c>1, msize(small) mlc(navy) mfc(white) msymbol(T)) ///
	(scatter asterisk c , msize(small) mlc(gs10) mfc(white) msymbol(+)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("RD coefficient (95% CI)", size(vsmall)) xtitle("") ///
	title("Outcome: Hours/day of commercial power", color(black) size(vsmall)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(0(0.2)1.2,nogrid angle(0) labsize(vsmall)) yscale(titlegap(*-4)) /// range(-0.125 0.4)) ///
	xlabel( 1 `" "Preferred" "'  ///
			2 `" "Kernel:" "Epanech-" "nikov" "' ///
			3 `" "Kernel:" "Uniform" "' ///
			4 `" "BW:" "MSE" "(sum)" "' ///
			5 `" "BW:" "CER" "(common)" "' ///
			6 `" "NN cluster" "by block" "' ///
			7 `" "Cluster" "by block" "' ///
			8 `" "Cluster" "by district" "' ///
			9 `" "No" "FEs" "' ///
			10 `" "District" "FEs" "' ///
			11 `" "2nd-order" "polynomial" "' ///
			12 `" "With" "pop" "mismatches" "' ///
			13 `" "With" "lights" " outliers" "' ///
			, labsize(vsmall)) ///
	legend(off) aspect(0.25)

graph export "$texfig/rd_vdelec_coeffs_sens_hcom.pdf", replace 

***

use "${results}/RDROBUST_fs_vdelec.dta", clear
keep if yvar=="vd_pwr_d_all_11"
keep if fals==""
keep if word(ifs,1)=="in_fs_sample==1"
gen c = .
replace c = 1 if ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<20" & fs_step==1
replace c = 2 if kernel=="Epanechnikov" & polynomial==1
replace c = 3 if kernel=="Uniform" & polynomial==1
replace c = 4 if bwmethod=="msesum"
replace c = 5 if bwmethod=="cerrd"
replace c = 6 if vce=="vce(nncluster stdtbk)"
replace c = 7 if vce=="vce(cluster stdtbk)"
replace c = 8 if vce=="vce(cluster stdt)"
replace c = 9 if fe==""
replace c = 10 if fe=="DTFE*"
replace c = 11 if kernel=="Triangular" & polynomial==2
replace c = 12 if ifs=="in_fs_sample==1 & lights_diff<20"
replace c = 13 if ifs=="in_fs_sample==1 & pop_mismatch20==0 & lights_diff<50"
keep if c!=.
unique c
assert r(unique)==r(N) & r(N)==13

gen lci10 = beta_robust - 1.645*se_robust
gen asterisk = .
replace asterisk = -0.01 if lci10>0 & lci_robust<0

twoway (rspike uci_robust lci_robust c if c==1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta_robust c if c==1, msize(small) mc(midblue) msymbol(O)) ///
	(rspike uci_robust lci_robust c if c>1, lstyle(ci) lw(medium) lcolor(gs10)) ///
	(scatter beta_robust c if c>1, msize(small) mlc(navy) mfc(white) msymbol(T)) ///
	(scatter asterisk c , msize(small) mlc(gs10) mfc(white) msymbol(+)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("RD coefficient (95% CI)", size(vsmall)) xtitle("") ///
	title("Outcome: Dummy for any power in all 3 sectors", color(black) size(vsmall)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(,nogrid angle(0) labsize(vsmall)) yscale(titlegap(*-4)) /// range(-0.125 0.4)) ///
	xlabel( 1 `" "Preferred" "'  ///
			2 `" "Kernel:" "Epanech-" "nikov" "' ///
			3 `" "Kernel:" "Uniform" "' ///
			4 `" "BW:" "MSE" "(sum)" "' ///
			5 `" "BW:" "CER" "(common)" "' ///
			6 `" "NN cluster" "by block" "' ///
			7 `" "Cluster" "by block" "' ///
			8 `" "Cluster" "by district" "' ///
			9 `" "No" "FEs" "' ///
			10 `" "District" "FEs" "' ///
			11 `" "2nd-order" "polynomial" "' ///
			12 `" "With" "pop" "mismatches" "' ///
			13 `" "With" "lights" " outliers" "' ///
			, labsize(vsmall)) ///
	legend(off) aspect(0.25)

graph export "$texfig/rd_vdelec_coeffs_sens_dall.pdf", replace 

***


   // MAKE FIGURE
file open tablewrite using "$texfig/figure_rd_vdelec_sens.tex", write text replace
 
file write tablewrite "\begin{figure}[p]\centering" _n
file write tablewrite "\caption{Sensitivities for village-level RD in 2011 electricity access}" _n
file write tablewrite "\label{fig:rd_vdelec_sens}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "{\includegraphics[width=\textwidth, trim={2mm 25mm 1mm 26mm}, clip]{${texfig_short}/rd_vdelec_coeffs_sens_dall.pdf}} " _n
file write tablewrite "{\includegraphics[width=\textwidth, trim={2mm 25mm 1mm 23mm}, clip]{${texfig_short}/rd_vdelec_coeffs_sens_dcom.pdf}} " _n
file write tablewrite "{\includegraphics[width=\textwidth, trim={2mm 27mm 1mm 23mm}, clip]{${texfig_short}/rd_vdelec_coeffs_sens_hcom.pdf}} " _n
file write tablewrite "\vspace{-7mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Each panel reports \texttt{rdrobust} point estimates and " _n
file write tablewrite "95\% confidence intervals, for sensitivity analysis on one of three outcomes from Table \ref*{tab:rd_vdelec}: " _n
file write tablewrite "all-sector power access dummy (top panel); commercial power access dummy (middle panel); " _n
file write tablewrite "and hours per day of commercial power supply (bottom panel). " _n
file write tablewrite "In each panel, the left-most point plots our preferred RD estimates from Table \ref*{tab:rd_vdelec}." _n
file write tablewrite "First, we compare Epanechnikov and uniform weighting kernels to our preferred triangular kernel."  _n
file write tablewrite "Next, we compare our preferred MSE-optimal bandwidth selection algorithm ({\tt mserd}) with " _n
file write tablewrite "the MSE-optimal bandwidth based on the sum ({\tt msesum}) rather than the difference, and with the " _n
file write tablewrite "coverage error rate optimal bandwidth algorithm ({\tt cerrd}). " _n
file write tablewrite "Next, we test alternative standard errors: nearest-neighbor clustering by Census block, " _n
file write tablewrite "clustering by Census block, and clustering by district. " _n
file write tablewrite "Next, we remove state fixed effects, and then add district fixed effects. " _n
file write tablewrite "Next, we use a quadratic polynomial in the running variable. " _n
file write tablewrite "Finally, we add in (i) the 11\% of villages with population " _n
file write tablewrite "discrepancies in merged habitation data, and (ii) the 0.2\% of villages with " _n
file write tablewrite "extremely implausible 10-year changes in nighttime brightness. " _n
file write tablewrite "Pluses indicate significance at the 10\% level, but not at the 5\% level. " _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Figure B3: RD for VD electricity, falsifications
{

use "${results}/RDROBUST_fs_vdelec.dta", clear
keep if inlist(yvar,"vd_pwr_d_com_11","vd_pwr_d_all_11","vd_pwr_h_com_11")
keep if fs_step==1 | fals!=""
keep if fe=="STFE*" | fe=="STFEH*"
assert kernel=="Triangular"
assert bwmethod=="mserd"
assert polynomial==1
gen c = .
replace c = 1 if fals=="" & fs_step==1
replace c = 2 if fals=="10th Plan, multi hab"
replace c = 3 if fals=="11th Plan, single hab"
replace c = 4 if fals=="11th Plan, multi hab"
assert c!=.


twoway (rspike uci_robust lci_robust c if c==1 & yvar=="vd_pwr_d_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==1 & yvar=="vd_pwr_d_com_11", msize(medlarge) mc(midblue) msymbol(O)) ///
	(rspike uci_robust lci_robust c if c==2 & yvar=="vd_pwr_d_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==2 & yvar=="vd_pwr_d_com_11", msize(medlarge) mlc(maroon) mfc(white) msymbol(0)) ///
	(rspike uci_robust lci_robust c if c==3 & yvar=="vd_pwr_d_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==3 & yvar=="vd_pwr_d_com_11", msize(medlarge) mc(maroon) msymbol(T)) ///
	(rspike uci_robust lci_robust c if c==4 & yvar=="vd_pwr_d_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==4 & yvar=="vd_pwr_d_com_11", msize(medlarge) mlc(maroon) mfc(white) msymbol(T)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("", size(medlarge)) xtitle("") ///
	title("Commercial" "Power Dummy", color(black) size(large)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(,nogrid angle(0) labsize(medlarge)) ///yscale(range(-0.125 0.4)) ///
	xlabel( 1 `" "10th" "Plan" " " "single" "hab" "'  ///
			2 `" "10th" "Plan" " " "multi" "hab" "' ///
			3 `" "11th" "Plan" " " "single" "hab" "' ///
			4 `" "11th" "Plan" " ""multi" "hab" "' ///
			, labsize(medlarge)) ///
	legend(off) aspect(.9)

graph export "$texfig/rd_vdelec_coeffs_falsif_dcom.pdf", replace 



twoway (rspike uci_robust lci_robust c if c==1 & yvar=="vd_pwr_d_all_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==1 & yvar=="vd_pwr_d_all_11", msize(medlarge) mc(midblue) msymbol(O)) ///
	(rspike uci_robust lci_robust c if c==2 & yvar=="vd_pwr_d_all_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==2 & yvar=="vd_pwr_d_all_11", msize(medlarge) mlc(maroon) mfc(white) msymbol(0)) ///
	(rspike uci_robust lci_robust c if c==3 & yvar=="vd_pwr_d_all_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==3 & yvar=="vd_pwr_d_all_11", msize(medlarge) mc(maroon) msymbol(T)) ///
	(rspike uci_robust lci_robust c if c==4 & yvar=="vd_pwr_d_all_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==4 & yvar=="vd_pwr_d_all_11", msize(medlarge) mlc(maroon) mfc(white) msymbol(T)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("RD coeff (95% CI)", size(medlarge)) xtitle("") ///
	title("3-Sector" "Power Dummy", color(black) size(large)) /// 
	///graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(-0.05 0 0.05,nogrid angle(0) labsize(medlarge)) ///yscale(range(-0.125 0.4)) ///
	xlabel( 1 `" "10th" "Plan" " " "single" "hab" "'  ///
			2 `" "10th" "Plan" " " "multi" "hab" "' ///
			3 `" "11th" "Plan" " " "single" "hab" "' ///
			4 `" "11th" "Plan" " ""multi" "hab" "' ///
			, labsize(medlarge)) ///
	legend(off) aspect(.9)

graph export "$texfig/rd_vdelec_coeffs_falsif_dall.pdf", replace 


twoway (rspike uci_robust lci_robust c if c==1 & yvar=="vd_pwr_h_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==1 & yvar=="vd_pwr_h_com_11", msize(medlarge) mc(midblue) msymbol(O)) ///
	(rspike uci_robust lci_robust c if c==2 & yvar=="vd_pwr_h_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==2 & yvar=="vd_pwr_h_com_11", msize(medlarge) mlc(maroon) mfc(white) msymbol(0)) ///
	(rspike uci_robust lci_robust c if c==3 & yvar=="vd_pwr_h_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==3 & yvar=="vd_pwr_h_com_11", msize(medlarge) mc(maroon) msymbol(T)) ///
	(rspike uci_robust lci_robust c if c==4 & yvar=="vd_pwr_h_com_11", lstyle(ci) lw(medthick) lcolor(gs10)) ///
	(scatter beta_robust c if c==4 & yvar=="vd_pwr_h_com_11", msize(medlarge) mlc(maroon) mfc(white) msymbol(T)) ///
	, ///
	yline(0, lcolor(black) lw(thin)) /// 
	ytitle("", size(medlarge)) xtitle("") ///
	title("Hours of" "Commercial Power", color(black) size(large)) /// 
	graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) ///
	ylabel(,nogrid angle(0) labsize(medlarge)) ///yscale(range(-0.125 0.4)) ///
	xlabel( 1 `" "10th" "Plan" " " "single" "hab" "'  ///
			2 `" "10th" "Plan" " " "multi" "hab" "' ///
			3 `" "11th" "Plan" " " "single" "hab" "' ///
			4 `" "11th" "Plan" " ""multi" "hab" "' ///
			, labsize(medlarge)) ///
	legend(off) aspect(.9)

graph export "$texfig/rd_vdelec_coeffs_falsif_hcom.pdf", replace 


   // MAKE FIGURE
file open tablewrite using "$texfig/figure_rd_vdelec_falsif.tex", write text replace
 
file write tablewrite "\begin{figure}[h!]\centering" _n
file write tablewrite "\caption{Falsification test for village-level RD in 2011 electricity access}" _n
file write tablewrite "\label{fig:rd_vdelec_falsif}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "{\includegraphics[width=.327\textwidth, trim={27mm 0mm 26mm 0mm}, clip]{${texfig_short}/rd_vdelec_coeffs_falsif_dall.pdf}} " _n
file write tablewrite "{\includegraphics[width=.327\textwidth, trim={27mm 0mm 26mm 0mm}, clip]{${texfig_short}/rd_vdelec_coeffs_falsif_dcom.pdf}} " _n
file write tablewrite "{\includegraphics[width=.327\textwidth, trim={27mm 0mm 26mm 0mm}, clip]{${texfig_short}/rd_vdelec_coeffs_falsif_hcom.pdf}} " _n
file write tablewrite "\vspace*{-7mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- This figure compares our main RD estimates to " _n
file write tablewrite "analogous RD estimates using three separate \`\`falsification'' samples of villages. " _n
file write tablewrite "All RDs apply the same specification as in Table \ref*{tab:rd_vdelec}, " _n
file write tablewrite "using 2001 Census populations as the running variables with a 300-person cutoff. " _n
file write tablewrite "Solid blue circles report our results in Table \ref*{tab:rd_vdelec}: Column (4), Panel A (left panel); " _n
file write tablewrite "Column (3), Panel A (middle panel); and Column (3), Panel B (right panel). " _n
file write tablewrite "These estimates use the subset of villages in RGGVY 10th-Plan districts (i.e.\ eligible for first-wave funding), " _n
file write tablewrite "with a single habitation (i.e.\ for which 2001 Census populations determined RGGVY eligibility). " _n
file write tablewrite "For multi-habitation villages, 2001 Census populations do not match the habitation-based 300-person " _n
file write tablewrite "cutoff---meaning that these RDs are using the wrong running variable. " _n
file write tablewrite "For villages in RGGVY 11th-Plan districts, the population cutoff was reduced to 100 " _n
file write tablewrite "people---meaning that these RDs are using the wrong cutoff. " _n
file write tablewrite "Whiskers display 95\% confidence intervals. " _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n

file close tablewrite

}

********************************************************************************
********************************************************************************

** Figure B5: RD for VD electricity, placebo tests
{
use "$results/RDROBUST_fs_vdelec.dta", clear
keep if fs_step==1 & yvar=="vd_pwr_d_all_11"
assert _N==1
local beta = beta_robust[1]
	
use "$sens/RDROBUST_placebo_test_vdelec_results.dta", clear
twoway (histogram d_all_fs_beta_robust, freq fcolor(navy) lcolor(black)) ///
       (scatteri 0 `beta' 800 `beta', msize(0) mcolor(red) connect(l) lwidth(thick) lcolor(red)), ///  
       xlabel(-0.05 0 0.05, labsize(medlarge)) ///
       ytitle("Count", size(medlarge)) title("2011 3-sector power dummy", size(large) color(black)) ///
			 legend(off) ylabel(,nogrid angle(0) labsize(medlarge)) xtitle("Placebo RD coefficients", size(medlarge)) ///
			 graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) //aspect(0.75)
graph export "$texfig/placebo_test_vdelec_rdrobust_dall.pdf", replace 
di `beta'
sum d_all_fs_beta_robust, detail
_pctile d_all_fs_beta_robust , p(91(1)99)
return list // above 96th percentile

use "$results/RDROBUST_fs_vdelec.dta", clear
keep if fs_step==1 & yvar=="vd_pwr_d_com_11"
assert _N==1
local beta = beta_robust[1]
	
use "$sens/RDROBUST_placebo_test_vdelec_results.dta", clear
twoway (histogram d_com_fs_beta_robust, freq fcolor(navy) lcolor(black)) ///
       (scatteri 0 `beta' 800 `beta', msize(0) mcolor(red) connect(l) lwidth(thick) lcolor(red)), ///  
       xlabel(-0.05 0 0.05, labsize(medlarge)) ///
       ytitle("Count", size(medlarge)) title("2011 commercial power dummy", size(large) color(black)) ///
			 legend(off) ylabel(,nogrid angle(0) labsize(medlarge)) xtitle("Placebo RD coefficients", size(medlarge)) ///
			 graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) //aspect(0.75)
graph export "$texfig/placebo_test_vdelec_rdrobust_dcom.pdf", replace 
di `beta'
sum d_com_fs_beta_robust, detail
_pctile d_com_fs_beta_robust , p(91(1)99)
return list // above 98th percentile


use "$results/RDROBUST_fs_vdelec.dta", clear
keep if fs_step==1 & yvar=="vd_pwr_h_com_11"
assert _N==1
local beta = beta_robust[1]
	
use "$sens/RDROBUST_placebo_test_vdelec_results.dta", clear
twoway (histogram h_com_fs_beta_robust, freq fcolor(navy) lcolor(black)) ///
       (scatteri 0 `beta' 800 `beta', msize(0) mcolor(red) connect(l) lwidth(thick) lcolor(red)), ///  
       xlabel(, labsize(medlarge)) ///
       ytitle("Count", size(medlarge)) title("2011 hours of commercial power", size(large) color(black)) ///
			 legend(off) ylabel(,nogrid angle(0) labsize(medlarge)) xtitle("Placebo RD coefficients", size(medlarge)) ///
			 graphregion(lcolor(white)) graphregion(color(white)) plotregion(fcolor(white)) //aspect(0.75)
graph export "$texfig/placebo_test_vdelec_rdrobust_hcom.pdf", replace 
di `beta'
sum h_com_fs_beta_robust, detail
_pctile h_com_fs_beta_robust , p(91(1)99)
return list // above 97th percentile



   // MAKE FIGURE
file open tablewrite using "$texfig/figure_rd_first_stage_placebo.tex", write text replace
 
file write tablewrite "\begin{figure}[h!]\centering" _n
file write tablewrite "\caption{Placebo tests for first-stage village-level RD estimates}" _n
file write tablewrite "\label{fig:rd_first_stage_placebo}" _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "{\includegraphics[width=0.45\textwidth, trim={2mm 0mm 2mm 0mm}, clip]{${texfig_short}/placebo_test_vdelec_rdrobust_dall.pdf}}~~~ " _n
file write tablewrite "{\includegraphics[width=0.45\textwidth, trim={2mm 0mm 2mm 0mm}, clip]{${texfig_short}/placebo_test_vdelec_rdrobust_dcom.pdf}} " _n
file write tablewrite "{\includegraphics[width=0.45\textwidth, trim={2mm 0mm 2mm 0mm}, clip]{${texfig_short}/placebo_test_vdelec_rdrobust_hcom.pdf}}~~~ " _n
file write tablewrite "{\includegraphics[width=0.45\textwidth, trim={2mm 0mm 2mm 0mm}, clip]{${texfig_short}/placebo_test_lights_rdrobust.pdf}} " _n
file write tablewrite "\vspace{-2mm}" _n
file write tablewrite "\caption*{\scriptsize Note. --- Each panel reports the density of  " _n
file write tablewrite "10,000 placebo RD estimates, which are otherwise identical to our preferred specification from Table  " _n
file write tablewrite "\ref*{tab:rd_vdelec}. We randomly generate 10,000 placebo cutoffs " _n
file write tablewrite "between 151 and 1000, excluding cutoffs between 275 and 325 (close to the true 300-person cutoff)." _n
file write tablewrite "The true RDs estimates (red dashed lines) fall above the 96th, 98th, 97th, and 99th percentiles of the placebo " _n
file write tablewrite "distributions for the 3-sector dummy, the commercial dummy, commercial hours of power, and 2011 nighttime brightness, respectively." _n
file write tablewrite "}" _n
file write tablewrite "\end{figure}" _n
 

file close tablewrite


}

********************************************************************************
********************************************************************************
